#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>

#define PATH "/dev/ap3216c"

int main(int argc, char* argv[])
{
    int fd, ret = 0;
    unsigned short buf[3] = {0};
    fd = open(PATH, O_RDWR);
    if (fd < 0) {
        printf("open error, errno %d [%s %d]\n", ret, __FUNCTION__, __LINE__);
        return fd;
    }
    while (1) {
        ret = read(fd, buf, sizeof(buf));
        if (ret < 0) {
            printf("read error, errno %d [%s %d]\n", ret, __FUNCTION__, __LINE__);
            break;
        } else if (ret == sizeof(buf)) {
            printf("als: %u\n", buf[0]);
            printf("ir: %u\n", buf[1]);
            printf("ps: %u\n", buf[2]);
        } 
        sleep(2);
    }

    close(fd);
    return ret;
}